package top.ffhome.system.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import top.ffhome.common.page.PageRequest;
import top.ffhome.common.result.Result;
import top.ffhome.system.service.SysAuditLogService;

@CrossOrigin
@RestController
@RequestMapping("api/log/audit")
@Api(tags = "系统审计日志控制器")
public class SysAuditLogController {
	@Autowired
	private SysAuditLogService auditLogService;

	@RequiresPermissions("system:auditlog:clean")
	@GetMapping("/clean")
	@ApiOperation(value = "清除审核日志")
	public Result clean() {
		auditLogService.clean();
		return Result.success();
	}

	@RequiresPermissions("system:auditlog:view")
	@PostMapping("/findPage")
	@ApiOperation("审核日志分页列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "params.dataId", value = "数据ID", dataType = "Long", paramType = "body"),
			@ApiImplicitParam(name = "params.entityNameLike", value = "对象模糊查询", dataType = "String", paramType = "body"),
			@ApiImplicitParam(name = "params.createTimeGte", value = "创建时间开始", dataType = "Date", paramType = "body"),
			@ApiImplicitParam(name = "params.createTimeLte", value = "创建时间结束", dataType = "Date", paramType = "body") })
	public Result findPage(@RequestBody PageRequest request) {
		return Result.success(auditLogService.select(request));
	}
}
